package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.ProjectRequest;
import com.smart.model.vo.ProjectVO;
import com.smart.model.vo.UnReportVO;
import com.smart.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author zyh
 */
@RestController
@RequestMapping("/project")
@Api(value = "云服务模块", tags = {"云服务#项目管理模块"})
public class CloudServerProjectController {

    @Autowired
    private ProjectService projectService;

    @WebAccess(login = true)
    @ApiOperation(value = "项目详情和项目编辑回显查询", httpMethod = "POST")
    @PostMapping("/selectProject")
    public WebResponse<ProjectVO> selectProject(@RequestParam("id") Long id) {
        return WebResponse.build(projectService.getByKey(id));
    }

    @ApiOperation("基础功能-注册")
    @PostMapping("/signIn")
    public WebResponse<String> signIn(@Valid @RequestBody ProjectRequest request, HttpServletRequest req) {
        return WebResponse.build(projectService.signIn(request, req));
    }

    @ApiOperation("根据项目编号/质量监督注册号精确搜索项目")
    @PostMapping("/pageQuery/{code}")
    public WebResponse<ProjectVO> queryProject(@PathVariable("code") String code) {
        return WebResponse.build(projectService.queryProject(code));
    }

    @WebAccess(login = true)
    @ApiOperation("云服务项目编辑")
    @PostMapping("/update")
    public WebResponse<String> updateByKey(@Valid @RequestBody ProjectRequest request, HttpServletRequest req) {
        return WebResponse.build(projectService.updateByKey(request, req));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "获取未提报数量", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getUnReport")
    public WebResponse<UnReportVO> getWeeklyUnReport() {
        return WebResponse.build(projectService.getUnReport());
    }
}
